package com.bysj.lms.controller;

import com.bysj.lms.common.ResultModel;
import com.bysj.lms.pojo.entity.CourseOutline;
import com.bysj.lms.pojo.entity.Test;
import com.bysj.lms.service.IRoleService;

import com.bysj.lms.utils.EasyExcelUtil;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.Date;
import java.util.List;

@Api(tags = "测试接口")
@RestController
@RequestMapping("/test")
public class TestController {

    @Autowired
    IRoleService roleService;

//    @Autowired
//    RoleMapper roleMapper;
//    @GetMapping("/hello")
//    public ResultModel test(){
//        List<Role> roles = roleService.getByUsername("wsnd");
//        roles.forEach(role -> System.out.println(role.toString()));
//        return ResultModel.success("成功",roles);
//    }
//
//    @PostMapping("/importExcel")
//    public ResultModel importExcel(@RequestParam("excel") MultipartFile excel){
//
//        List<Test> testsest = ExcelUtil.importExcel(excel, Test.class);
//
//        testsest.forEach(a-> System.out.println(a.toString()));
//        return null;
//    }

    @Autowired
    JavaMailSender javaMailSender;
    @GetMapping("/mail")
    public ResultModel sendMail(){
        // 构建一个邮件对象
        SimpleMailMessage message = new SimpleMailMessage();
        //邮件设置
        //设置邮件主题
        message.setSubject("波波");
        //设置邮件发送者，这个跟application.yml中的设置要一致
        message.setFrom("1473727528@qq.com");
        //设置邮件接收者，可以有多个接收者，中间用逗号隔开
        message.setTo("xiaojiakai@aliyun.com");
        //设置邮件发送日期
        message.setSentDate(new Date());
        //设置邮件的正文
        message.setText("波波收到邮件滴滴我一下");
        //发送邮件
        javaMailSender.send(message);
        return ResultModel.success("发送成功");
    }

    @PostMapping("/course")
    public void importExcel(@RequestParam("/excel") MultipartFile file) throws IOException {
        List<Test> read = EasyExcelUtil.read(file, Test.class, 2);
        System.out.println(read);
    }
}
